package org.xx.armory.docs;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 * 表格行元素。
 *
 * @author Haart
 */
public class TableRow
        extends Block
        implements List<TableCell> {
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private final List<TableCell> cells;

    /**
     * 构造表格行元素。
     *
     * @param className
     *         表格行元素的类名, 会被正规化。
     */
    public TableRow(String className) {
        super(className);

        this.cells = new ArrayList<>();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final int size() {
        return this.cells.size();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean isEmpty() {
        return this.cells.isEmpty();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean contains(Object o) {
        return this.cells.contains(o);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final Iterator<TableCell> iterator() {
        return this.cells.iterator();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final Object[] toArray() {
        return this.cells.toArray();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    @SuppressWarnings("SuspiciousToArrayCall")
    public final <T> T[] toArray(T[] a) {
        return this.cells.toArray(a);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean add(TableCell e) {
        return this.cells.add(e);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean remove(Object o) {
        return this.cells.remove(o);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean containsAll(Collection<?> c) {
        return this.cells.containsAll(c);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean addAll(Collection<? extends TableCell> c) {
        return this.cells.addAll(c);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean addAll(
            int index,
            Collection<? extends TableCell> c
    ) {
        return this.cells.addAll(index, c);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean removeAll(Collection<?> c) {
        return this.cells.removeAll(c);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean retainAll(Collection<?> c) {
        return this.cells.retainAll(c);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void clear() {
        this.cells.clear();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final TableCell get(int index) {
        return this.cells.get(index);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final TableCell set(
            int index,
            TableCell element
    ) {
        return this.cells.set(index, element);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void add(
            int index,
            TableCell element
    ) {
        this.cells.add(index, element);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final TableCell remove(int index) {
        return this.cells.remove(index);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final int indexOf(Object o) {
        return this.cells.indexOf(o);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final int lastIndexOf(Object o) {
        return this.cells.lastIndexOf(o);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final ListIterator<TableCell> listIterator() {
        return this.cells.listIterator();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final ListIterator<TableCell> listIterator(int index) {
        return this.cells.listIterator(index);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final List<TableCell> subList(
            int fromIndex,
            int toIndex
    ) {
        return this.cells.subList(fromIndex, toIndex);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("<tr>");
        for (final TableCell cell : this.cells) {
            sb.append(cell);
        }
        sb.append("</tr>");
        return sb.toString();
    }
}
